/**
 * 按钮地洞的逻辑脚本
 * Author   :jxyi
 * Date     :2017-3-20
 */

const Status = {
    normal  : 0,
    mouse   : 1,
    wrong   : 2
};

cc.Class({
    extends: cc.Component,

    properties: {
        
    },

    // use this for initialization
    onLoad: function () {
        this.status = Status.normal;

        this.node.on(cc.Node.EventType.TOUCH_END, this.onClicked, this);
    },

    onClicked: function(event) {
        if (this.status == Status.mouse){
            this.node.color = cc.Color.GREEN;
            this.status = Status.normal;
            this.schedule(function(){
                this.node.color = cc.Color.WHITE;
            }, 0.1);
            this.node.dispatchEvent(new cc.Event.EventCustom('addScore', true));
        }
        else if (this.status == Status.normal) {
            this.status = Status.wrong;
            this.node.color = cc.Color.RED;

            this.unscheduleAllCallbacks();

            this.schedule(function(){
                this.status = Status.normal;
                this.node.color = cc.Color.WHITE;
            }, 1);

            this.node.dispatchEvent(new cc.Event.EventCustom('desScore', true));
        }
        else {
            // do nothing
        }
    },

    addShrewmouse: function(){
        if (this.status == Status.normal){
            this.status = Status.mouse;
            this.node.color = cc.Color.BLUE;

            this.unscheduleAllCallbacks();
            this.schedule(function(){
                this.status = Status.normal;
                this.node.color = cc.Color.WHITE;
            }, 1);
        }
        else {
            // do nothing
        }
    },
});
